 export class EventBus {
    constructor () {
        this.eventObj = {}
    }

    static getInstance () {
        if (!this.instance) {
            this.instance = new EventBus()
        }
        return this.instance
    }

    // 订阅事件
    on (eventName, fn) {
        if (!this.eventObj[eventName]) {
            this.eventObj[eventName] = []
        }
        this.eventObj[eventName].push(fn)
    }
    // 触发事件并传参
    emit (eventName, ...args) {
        this.eventObj[eventName].forEach(fn => {
            fn(...args)
        })
    }
 }